﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BooksManagermentSystem
{
    public partial class UpdatePress_form : Form
    {
        public UpdatePress_form()
        {
            InitializeComponent();
        }

        private void UpdatePress_form_Load(object sender, EventArgs e)
        {
            Show();
        }

        private void Show()
        {
            DataTable dt = DBhelper.GetDataTable("select * from Press");
            comboBox1.DataSource = dt;
            comboBox1.DisplayMember = "pressname";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string newpressname = textBox1.Text;
            string oldpressname = comboBox1.Text;

            if(newpressname.Length == 0)
            {
                MessageBox.Show("请输入出版社名");
                textBox1.Focus();
                return;
            }

            DialogResult rt = MessageBox.Show($"确定要把【{oldpressname}】改为【{newpressname}】吗？", "提示", MessageBoxButtons.YesNo);
            if(rt == DialogResult.Yes)
            {
                string sql = $"update Press set pressname = '{newpressname}' where pressname = '{oldpressname}'";
                if(DBhelper.NonQuery(sql))
                {
                    MessageBox.Show("修改成功！");
                    textBox1.Clear();
                    Show();
                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }
        }
    }
}
